package Demo1;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Administrator
 * Date: 2024-09-30
 * Time: 18:54
 */
public class CardList {

    public static final String[] SUITS = {"♦", "♥︎", "♠", "♣"};

    public static void shuffle(List<Card> list){
        Random random = new Random();
        for (int i = list.size() - 1; i > 0 ; i--) {
            int index = random.nextInt(i);
            swap(list,i,index);
        }

    }


    public static void swap(List<Card> list,int i,int j){
        Card tmp = list.get(i);
        list.set(i,list.get(j));
        list.set(j,tmp);
    }
    
    public static List<Card> buyCards() {
        List<Card> list = new ArrayList<>();
        for (int i = 0; i < SUITS.length; i++) {
            for (int j = 1; j <= 13; j++) {
                Card card = new Card(SUITS[i], j);
                list.add(card);
            }
        }
        return list;
    }



    public static void main(String[] args) {
        List<Card> list = buyCards();
        System.out.println(list);
        shuffle(list);
        System.out.println(list);

        List<List<Card>> hand= new ArrayList<>();
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();

        for (int i = 0; i < 3; i++) {
            hand.add(hand1);
            hand.add(hand2);
            hand.add(hand3);
        }

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = list.remove(0);
                hand.get(j).add(card);
            }
        }
        System.out.print("第一个人的牌：" + hand.get(0));
        System.out.println();
        System.out.print("第二个人的牌：" + hand.get(1));
        System.out.println();
        System.out.print("第三个人的牌：" + hand.get(2));
        System.out.println();
        System.out.print("剩下的牌" + list);
        System.out.println();
    }
}